package com.summer.common.lib.core.validator.customize;

import com.summer.common.lib.core.validator.annotations.PwdValid;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;

public class PwdValidator implements ConstraintValidator<PwdValid, String> {

    private int min;

    private int max;

    @Override
    public void initialize(PwdValid constraintAnnotation) {
        this.min = constraintAnnotation.min();
        this.max = constraintAnnotation.max();
    }

    @Override
    public boolean isValid(String value, ConstraintValidatorContext context) {
        return value.length() >= min && value.length() <= max;
    }
}
